//
//  ZYTabBarViewController.m
//  YaYa
//
//  Created by 张亚 on 2019/1/8.
//  Copyright © 2019年 张亚. All rights reserved.
//

#import "ZYTabBarViewController.h"
#import "ZYTabBar.h"
#import "ZYNavgationViewController.h"
#import "ZYLaunchViewController.h"

@interface ZYTabBarViewController ()<ZYTabBarDelegate>

@property (nonatomic, strong) ZYTabBar * zyTabBar;

@end

@implementation ZYTabBarViewController

- (ZYTabBar *)zyTabBar {
    if (_zyTabBar == nil) {
        _zyTabBar = [[ZYTabBar alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, kTabbarHeight)];
        _zyTabBar.delegate = self;
    }
    return _zyTabBar;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    //加载控制器
    [self configViewController];
    //加载tabBar
    [self.tabBar addSubview:self.zyTabBar];
    
    [[UITabBar appearance] setShadowImage:[[UIImage alloc]init]];
    [[UITabBar appearance] setBackgroundImage:[[UIImage alloc] init]];
}

- (void)configViewController {
    NSMutableArray * array = [NSMutableArray arrayWithObjects:@"ViewController",@"ZYMainViewController",@"ZYMeViewController",nil];
    for (int i = 0; i < array.count; i++) {
        NSString * vcName = array[i];
        
        UIViewController * vc = [[NSClassFromString(vcName) alloc] init];
        
        ZYNavgationViewController * nav = [[ZYNavgationViewController alloc] initWithRootViewController:vc];
        
        [array replaceObjectAtIndex:i withObject:nav];
        
        
    }
    self.viewControllers = array;
    
}

#pragma mark - ZYTabBarDelegate
- (void)tabbar:(ZYTabBar *)tabbar clickButton:(ZYTabBarItemType)idx {
    if (idx != ZYTabBarItemTypeLaunch) {
        self.selectedIndex = idx - ZYTabBarItemTypeLive;
        return;
    }
    
    ZYLaunchViewController * launchVC = [[ZYLaunchViewController alloc] init];
    [self presentViewController:launchVC animated:YES completion:nil];
}



@end
